//import UIKit
//import LBXScan
//import AVFoundation
//
//class ScanCodeManager: NSObject {
//    
//    enum ScanType {
//        case qrCode
//        case barCode
//        case all
//        
//        var metadataTypes: [AVMetadataObject.ObjectType] {
//            switch self {
//            case .qrCode:
//                return [.qr, .pdf417, .aztec]
//            case .barCode:
//                return [.ean13, .ean8, .code128, .code39, .code93, .code39Mod43, .upce]
//            case .all:
//                return [.qr, .pdf417, .aztec, .ean13, .ean8, .code128, .code39, .code93, .code39Mod43, .upce]
//            }
//        }
//    }
//    
//    private var scanViewController: SaomaViewController?
//    private var completion: ((Result<String, Error>) -> Void)?
//    
//    func showScanner(from viewController: UIViewController,
//                    scanType: ScanType = .all,
//                    completion: ((Result<String, Error>) -> Void)? = nil) {
//        self.completion = completion
//        
//        let scanner = SaomaViewController()
//        self.scanViewController = scanner
//        
//        // 配置扫码参数
//        scanner.scanStyle = configureScanStyle(for: scanType)
//        scanner.supportedBarcodeTypes = scanType.metadataTypes
//        scanner.scanResultDelegate = self
//        
//        viewController.navigationController?.pushViewController(scanner, animated: true)
//    }
//    
//    private func configureScanStyle(for scanType: ScanType) -> LBXScanViewStyle {
//        var style = LBXScanViewStyle()
//        
//        // 基本配置
//        style.centerUpOffset = 44
//        style.photoframeAngleStyle = .Inner
//        style.photoframeLineW = 4
//        style.photoframeAngleW = 28
//        style.photoframeAngleH = 16
//        style.isNeedShowRetangle = true
//        
//        // 根据扫码类型调整
//        switch scanType {
//        case .qrCode:
//            style.whRatio = 1.0
//            style.anmiationStyle = .NetGrid
//        case .barCode:
//            style.whRatio = 4.3/2.18
//            style.anmiationStyle = .LineStill
//        case .all:
//            style.whRatio = 1.0
//            style.anmiationStyle = .LineMove
//        }
//        
//        style.colorRetangleLine = UIColor(red: 0.0, green: 0.7, blue: 0.0, alpha: 1.0)
//        style.colorAngle = UIColor(red: 0.0, green: 0.7, blue: 0.0, alpha: 1.0)
//        style.xScanRetangleOffset = 60
//        
//        return style
//    }
//}
//
//extension ScanCodeManager: LBXScanViewControllerDelegate {
//    func scanFinished(scanResult: LBXScanResult, error: String?) {
//        if let error = error {
//            completion?(.failure(NSError(domain: "ScanError", code: -1, userInfo: [NSLocalizedDescriptionKey: error])))
//        } else if let code = scanResult.strScanned {
//            completion?(.success(code))
//        } else {
//            completion?(.failure(NSError(domain: "ScanError", code: -2, userInfo: [NSLocalizedDescriptionKey: "未识别到有效条码"])))
//        }
//        
//        scanViewController?.navigationController?.popViewController(animated: true)
//        scanViewController = nil
//    }
//}
